import {createRouter, createWebHashHistory} from "vue-router";

const routes = [
    {
        path: '/',
        component: () =>
            import ( '@/layouts'),
        meta: {
            title: '首页'
        },
        children: [
            {
                path: 'home',
                component: () =>
                    import (  '@/view/home'),
                meta: {
                    title: '首页'
                },
            }
        ]
    },
    // {
    //   path: "/",
    //   component: () => import(/* webpackChunkName: "home" */ "@/view/home.vue"),
    //   meta: {
    //     title: "首页",
    //   },
    // },
    {
        path: "/dataV/home",
        component: () =>
            import(/* webpackChunkName: "home" */ "@/view/dataV/home.vue"),
        meta: {
            title: "大屏首页",
        },
    },
    {
        path: "/login",
        component: () => import("@/view/login"),
        meta: {
            title: "登录",
        },
    },
    {
        path: "/404",
        component: () => import("@/view/404"),
    },
    {
        path: "/:pathMatch(.*)*",
        redirect: "/404",
    },
]

// 导航守卫
/* // 判断用户是否登录，添加前置导航守卫
router.beforeEach((to, from, next) => {
    document.title = `${to.meta.title}`;
    const sign = localStorage.getItem('sign');
    if (sign) {
        next()
    } else {
        if (to.path === '/login') { // 如果是登录页
            next();
        } else {
            next({ path: '/login' })
        }
    }
}) */
export default createRouter({
    history: createWebHashHistory(),
    routes,
});
